package com.banwoqiche.controller;

import com.banwoqiche.dto.MyBackInfo;
import com.banwoqiche.pojo.SysUser;
import com.banwoqiche.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * @time: 2022-03-30 13:42
 */
@RestController
@RequestMapping("/userManage")
public class UserController {
    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    @PreAuthorize("hasAnyAuthority('userManage','userManage:get:byAcc')")
    @PostMapping("/get/byAcc")
    public MyBackInfo getUserByacc(String userAcc) {
        return MyBackInfo.backInfo(userService.getByacc(userAcc));
    }

    @PreAuthorize("hasAnyAuthority('userManage','userManage:get:byMobile')")
    @PostMapping("/get/byMobile")
    public MyBackInfo getUserBymob(String userMoble) {
        return MyBackInfo.backInfo(userService.getBymobile(userMoble));
    }

    @PreAuthorize("hasAnyAuthority('userManage','userManage:add')")
    @PostMapping("/add")
    public MyBackInfo addUser(@RequestBody SysUser sysUser) {
        SysUser copyUser = new SysUser();
        BeanUtils.copyProperties(sysUser, copyUser);
        userService.insertUser(copyUser);
        return MyBackInfo.backInfo();

        @PreAuthorize("hasAnyAuthority('userManage','userManage:update')")
        @PostMapping("/update")
        public MyBackInfo updateInfo (@RequestBody CUser sysUser){
            SysUser copyUser = new SysUser();
            BeanUtils.copyProperties(sysUser, copyUser);
            userService.updateByuser(copyUser);
            return MyBackInfo.backInfo();

            return MyBackInfo.backInfo();

        }
    }}